package com.hxzf.mvp.web.controller;

import com.hxzf.mvp.commons.BaseController;
import com.hxzf.mvp.commons.domain.Resp;
import com.hxzf.mvp.dao.entity.Dict;
import com.hxzf.mvp.service.DictService;
import com.hxzf.mvp.service.impl.DictServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

/**
 * 数据字典接口
 *
 * <p>演示简单的CRUD操作，可以使用MPG自动生成接口。
 *
 * @author Kai
 * @date 2021/6/25 9:01
 **/
@Api(value = "DictController", tags = "数据字典")
@RestController
@RequestMapping("/dict")
public class DictController extends BaseController {
    private final DictService dictService;

    public DictController(DictServiceImpl dictService) {
        this.dictService = dictService;
    }

    @ApiOperation(value = "字典详情", notes = "根据ID查询数据字典。")
    @GetMapping(value = "/{id}")
    public Resp<Dict> queryDetails(@RequestParam Long id) {
        return ok(dictService.getById(id));
    }

    @ApiOperation(value = "字典列表", notes = "分页查询数据字典数据。")
    @PostMapping(value = "/list")
    public Resp<Dict> doQuery(@RequestBody Dict query) {
        return page(dictService.list(query));
    }

    @ApiOperation(value = "字典新增", notes = "新增数据字典。")
    @PostMapping(value = "/add")
    public Resp<?> doAdd(@RequestBody Dict dict) {
        return ok(dictService.save(dict));
    }

    @ApiOperation(value = "字典修改", notes = "修改数据字典。")
    @PostMapping(value = "/edit")
    public Resp<?> doChange(@RequestBody Dict dict) {
        return ok(dictService.modify(dict));
    }

    @ApiOperation(value = "字典删除", notes = "批量删除数据字典。")
    @PostMapping(value = "/remove")
    public Resp<?> doRemove(@RequestParam Long[] ids) {
        return ok(dictService.removeByIds(ids));
    }
}
